<!DOCTYPE html>
<html lang="en">
<head>
    <title>登录管理</title>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/layui/css/layui.css"/>
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<div class="demoTable">
    名称：
    <div class="layui-inline">
        <input class="layui-input" name="name" id="name" autocomplete="off">
    </div>
    <button class="layui-btn" id="searchBtn" data-type="reload">搜索</button>
    <input class="layui-btn" type="button" id="export" value="导出">
</div>
<table class="layui-hide" id="test" lay-filter="test"></table>
<!-- 自定义的控件 -->
<div id="toolbar" style="display: none; ">
    <!-- <div class="layui-btn-group">
    <button class="layui-btn layui-btn-sm" lay-event="add" datamethod="notice" data-type="auto">添加</button>
    </div>
    <div class="layui-btn-group">
    <button class="layui-btn layui-btn-sm" data-method="notice" datatype="auto">导出</button>
    </div>-->
</div>
<script src="/layui/layui.js" charset="utf-8"></script>
<script>
    layui.use(['table', 'layer', 'form', 'jquery'], function () {
        var form = layui.form;
        var table = layui.table;
        var layer = layui.layer;
        var $ = layui.jquery;
        table.render({
            elem: '#test'
            , url: '/api/loginInfor/page'
// , height: document.body.clientHeight - 180
            , page: true //开启分页
            , id: 'testReload'
            , cols: [[
                {field: "id", title: "序号"},
                {field: "username", title: "用户名称"},
                {field: "loginIp", title: "IP地址"},
                {field: "loginBroswer", title: "浏览器"},
                {field: "loginAddress", title: "位置"},
                {
                    field: "createDatetime",
                    title: "时间"
                }
            ]]
            , response: { // 设置响应码
                statusCode: 1 //规定成功的状态码，默认：0
            },
            parseData: function (rs) {//数据格式解析
                if (rs.status == 1) {
                    return {
                        "code": rs.status,
                        "msg": rs.message,
                        "count": rs.total,
                        "data": rs.data
                    }
                }
            }
        });
//弹出导出页面
        $(document).on('click', '#export', function () {
            window.location.href = "/api/loginInfor/export?username=" + $("#name").val();
        });
        var active = {
            reload: function () {
                var username = $('#name');
//执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: {
                        "username": username.val()
                    }
                });
            }
        };
        $('.demoTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>
</body>
</html>